<template>
	<view class="mine-page page">
		<CustomNav title="实时预警通知" :isBack="true"></CustomNav>
		<view class="info-block">
			<view class="info-list">
				<view class="title">{{info.title}}</view>
				<view class="form-item">
					<view class="name-item">
						<view class="name">灾害类型</view>
					</view>
					<view class="form-content">
						<view class="form-crl">{{info.type}}</view>
					</view>
				</view>
				<view class="form-item">
					<view class="name-item">
						<view class="name">位置</view>
					</view>
					<view class="form-content">
						<view class="form-crl">{{info.province}}{{info.city}}{{info.area}}</view>
						<!-- <view class="right">
							<view class="iconfont icon-daohang"></view>
							<view class="distance">{{info.distance}}km</view>
						</view> -->
					</view>
				</view>
				<view class="form-item">
					<view class="name-item">
						<view class="name">发生时刻</view>
					</view>
					<view class="form-content">
						<view class="form-crl">{{info.time}}</view>
					</view>
				</view>
				<view class="form-item">
					<view class="name-item">
						<view class="name">预计影响范围</view>
					</view>
					<view class="form-content">
						<mp-html :content="info.text"></mp-html>
					</view>
				</view>
				<view class="form-item" v-if="info.pdf">
					<view class="name-item">
						<view class="name">文件</view>
					</view>
					<view class="form-content1" @click="open(info.pdf)">
						<image src="../../static/image/pdf-icon.png" class="img"></image>
						<view class="name">{{info.pdfName}}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getWarningById
	} from '@/api/contact.js'
	export default {
		data() {
			return {
				info: {
					title: '',
					type: '',
					province: '',
					city: '',
					area: '',
					time: '',
					text: ''
				},
				id: null
			}
		},
		methods: {
			//onShareAppMessage 分享给朋友
			//onShareTimeline  分享到朋友圈
			// #ifdef MP
			onShareAppMessage: function(res) {
				if (res.from === 'button') {
					// 来自页面内转发按钮
					console.log(res.target)
				}
				return {
					title: this.info.title,
					path: '/page_pack/notice/detail?id=' + this.info.id
				}
			},
			// #endif
			onShareTimeline(res) {
				let distSource = uni.getStorageSync('distSource');
				if (distSource) {
					return {
						title: this.info.title,
						path: '/page_pack/notice/detail?id=' + this.info.id,
						type: 0,
						query: 'id=' + distSource,
					}
				}
			},
			getDetail() {
				getWarningById({
					id: this.id
				}).then(res => {
					this.info = res
				}).finally(() => {
					uni.stopPullDownRefresh();
				})
			},
			open(url) {
				uni.downloadFile({
					url: url,
					success: function(res) {
						var filePath = res.tempFilePath;
						uni.openDocument({
							filePath: filePath,
							showMenu: true,
							success: function(res) {
								console.log('打开文档成功');
							}
						});
					}
				});
			}
		},
		onLoad(e) {
			this.id = e.id
			this.getDetail()
		}
	}
</script>

<style lang="scss" scoped>
	.mine-page {
		overflow: hidden;

		.info-block {
			margin-top: 23%;
			padding: 30rpx;
			background-color: #F7F6F9;
			min-height: 80vh;

			.info-list {
				background-color: #fff;
				border-radius: 20rpx;
				padding: 30rpx;
				margin-bottom: 20rpx;

				.title {
					width: 100%;
					font-size: 36rpx;
					font-weight: bold;
					// overflow: hidden;
					// text-overflow: ellipsis;
					// white-space: nowrap;
				}

				.form-item:last-child {
					border-bottom: none;
				}

				.form-item {
					display: flex;
					flex-direction: column;
					border-bottom: 1px solid #F7F7F7;
					padding-bottom: 30rpx;
					margin-top: 30rpx;

					.name-item {
						display: flex;
						align-items: center;
						margin-bottom: 30rpx;

						.name {
							font-size: 30rpx;
						}
					}

					.form-content1 {
						display: flex;
						flex-direction: column;
						align-items: flex-start;

						.img {
							width: 130rpx;
							height: 145rpx;
						}

						.name {
							font-size: 14px;
						}
					}

					.form-content {
						display: flex;
						align-items: center;
						justify-content: space-between;
						width: 100%;

						.form-crl1 {
							width: calc(100% - 140rpx);
						}

						.form-crl {
							width: 100%;
						}

						.right {
							display: flex;
							align-items: center;

							.iconfont {
								margin-right: 10rpx;
								color: #3466FF;
								font-size: 32rpx;
							}

							.distance {
								color: #767676;
								font-size: 28rpx;
							}
						}
					}
				}
			}
		}
	}
</style>